<template>
  <div>

    <div class="container">
      <el-select v-model="reason" placeholder="请选择退货原因">
        <el-option v-for="item in reasonList" :label="item.name" :value="item.name"></el-option>
      </el-select>
      <el-input
          type="textarea"
          :autosize="{ minRows: 10, maxRows: 15}"
          placeholder="详细原因"
          v-model="description"
          style="margin-top: 50px">
      </el-input>
      <div style="margin-top: 50px;text-align: center">
        <el-button type="primary" @click="submit">提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {createReturnApply} from "@/api/returnApply";
import {fetchList} from "@/api/returnReason";

export default {
  name: "ReturnApply",
  props: {
    productId: {
      type: Number,
      default: 1
    },
    memberId: {
      type: String,
      default: 1
    },
    orderId: {
      type: String,
      default: 1
    }
  },
  data() {
    return {
      orderReturnApplyId: 0,
      reason: "",
      description: "",
      reasonList:[],
    }
  },
  watch: {
    memberId: {
      handler(val) {
        this.memberId = val;
      },
      immediate: true
    },
    productId: {
      handler(val) {
        this.productId = val;
        this.getReasonList();
      },
      immediate: true
    },
    orderId:{
      handler(val) {
        this.orderId = val;
        this.getReasonList()
      },
      immediate: true
    }
  },
  methods: {
    submit() {
      let params = {
        memberId: this.memberId,
        productId: this.productId,
        orderId: this.orderId,
        reason: this.reason,
        description: this.description,
      }
      createReturnApply(params).then(res => {
        this.$message.success("退货申请成功");
        location.reload();
      })
    },
    getReasonList(){
      fetchList().then(res => {
        this.reasonList = res.data.list;
      })
    }
  }
}
</script>

<style>

</style>